/**
* @file rtcommon.h in loosely_couple_h7
* @author rebeater
* @comment tool funcitons for real time application
* Create on 3/24/21 3:38 PM
* @version 1.0
**/

//
// Created by rebeater on 3/24/21.
//

#ifndef LOOSELY_COUPLE_H7_RTCOMMON_H
#define LOOSELY_COUPLE_H7_RTCOMMON_H
#include "global_defines.h"

#include "usart.h"
/*
#if IMU_DEVICE == IMU_ADIS16460
#include "adis16460.h"
#define IMU_RAW ImuRawAdi
#define RAW_TO_IMU(X,Y) convert_adi_to_double(X,Y)
#define INIT_IMU_DEVICE()  adis16460_init()
#define READ_IMU_FIFO(X,ID) adis16460_burst_read(X)
#elif IMU_DEVICE == IMU_KYIMU102
#include "bdkyimu.h"
#define IMU_RAW ImuRawKy
#define RAW_TO_IMU(X,Y) ConvertKyToDouble(X,Y)
#define INIT_IMU_DEVICE() KyImu102A0Initial()
#define READ_IMU_FIFO(X,ID) KyImu102A0ReadRaw(X)
#elif IMU_DEVICE == IMU_ICM20602
#include "icm20602.h"
#define IMU_RAW ImuRawIcm
#if ENABLE_MULTI_IMUS==1
#define INIT_IMU_DEVICE() Icm20602MultiInit(IMU_MODE_CAR, IMU_RATE_50Hz)
#else
#define INIT_IMU_DEVICE() icm20602_init_spi(IMU_MODE_CAR, IMU_RATE_50Hz,icm20602_id)
#endif
#define RAW_TO_IMU(X,Y) convert_icm_to_double(X,Y)
#define READ_IMU_FIFO(X,ID) icm20602_read_fifo(X,ID)
#elif IMU_DEVICE == IMU_STIM300
#include <stim300.h>
#define RAW_TO_IMU(X,Y) stim300_convert_to_imu(X,Y)
#define INIT_IMU_DEVICE() Stim300UartInit()
#else
#error("IMU Device NOT SUPPORTED!")
#endif*/

#define MAJOR_VERSION 3
#define MINOR_VERSION 2
#define BUILD_VERSION 14

typedef struct {
  unsigned char year;
  unsigned char mon;
  unsigned char day;
  unsigned char hour;
  unsigned char minute;
  unsigned char second;
} DateTime;

extern char Version[];
extern const char Description[];
extern char GnssDeviceName[];
//extern char Comments[];
extern char ImuName[];
extern char FileNameFormat[];
double GetCurrentGpst();
void printDouble(double d, uint8_t n);
void sprintDouble(char *buffer, double d, uint8_t n);
void gpst_to_utc(int week, double gpst, DateTime *time);
uint32_t crc_checksum(const uint8_t *indata, int num_bytes);
int day_from_gps0(const int year, const int mon, const int day);
typedef enum {
  Info,
  Warning,
  Error,
  Fetal,
  } TraceLevel;

/**
 * 日志打印函数
 * @param level 日志等级
 * @param fmt  format
 * @param ...
 * @return 02
 */
extern char kUart6TxBuffer[512] ;
int trace(TraceLevel level, const char *fmt, ...) __attribute__((format(printf,2,3)));
int traceDMA(TraceLevel level, const char *fmt, ...) __attribute__((format(printf,2,3)));
int CommonTrace(const char *fmt, ...) ;
void TraceInit();
#endif //LOOSELY_COUPLE_H7_RTCOMMON_H
